﻿using System;
using System.Buffers;
using System.IO;


namespace tcp_connection;

public class ServerTcpConnection : ATcpConnection
{
    public override void OnActive()
    {
        base.OnActive();
        System.Threading.Interlocked.Increment(ref ServerStatistics.client_count);
        Console.WriteLine("服务端=======一个channel被打开" + Id);
    }

    int index = 0;

    protected override async void OnMessage(ReadOnlySequence<byte> buf)
    {
        index++;
        //Console.WriteLine($"服务端:{index}::" + System.Text.Encoding.UTF8.GetString(buf.ToArray()));

        this.InternalWrite(ref buf);
        await FlushAsync();
    }

    public override void OnInactive()
    {
        base.OnInactive();
        Console.WriteLine("服务端=======一个channel被关闭");
    }
}